#
# Copyright (C) 2011
#
# Brick Yang <printfxxx@163.com>
#
# This program is free software. You can redistribute it and/or
# modify it as you like.
#

##
# File		Makefile
# Brief		Makefile for brick_utils.
#

# === Project Configuration ===
# Project name
project = brick_utils

# === Arch Configuration
ARCH ?= $(ARCH_$(shell uname -m))
ARCH_aarch64 = arm64
ARCH_ppc = powerpc

# === Objs, subdirs, targets ===
obj-$(CONFIG_MTOOL)      += mtool/
obj-$(CONFIG_MDIO_TOOL)  += mdio_tool/
obj-$(CONFIG_SIMPLEBITS) += simplebits/
obj-$(CONFIG_PMU)        += pmu/

# === Flags For Compiler & Linker ===
# Flags to give to C compiler
CFLAGS += -O2 -g3 -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
	  -Werror-implicit-function-declaration -Wno-format-security -Wno-sign-compare \
	  -Wno-unused-but-set-variable -Wdeclaration-after-statement -Wno-pointer-sign \
	  -I$(CURDIR)/mtrace
# Flags to give to assembler
ASFLAGS +=
# Flags to give to C++ compiler
CXXFLAGS +=
# Flags to give to linker
LDFLAGS +=
# Flags to give to C compiler for kernel modules
KCFLAGS += -I$(CURDIR)/mtrace

# === Mconf Options ===
# Mconf config file
mcfg = Kconfig
MCONF = opt/mconf
MCONF_ENV = ARCH=$(ARCH)

ifeq ($(CONFIG_DEBUG),y)
CFLAGS  += -DDEBUG
KCFLAGS += -DDEBUG
endif

ifeq ($(CONFIG_MTRACE),y)
obj-y += mtrace/

CFLAGS  += -DMTRACE
LDFLAGS += -L$(optdir) -lmtrace
KCFLAGS += -DMTRACE

build-mtool build-mdio_tool build-simplebits build-pmu: build-mtrace
endif

ifneq ($(filter kconfig,$(MAKECMDGOALS)),)
CROSS_COMPILE =
PKG_CONFIG_LIBDIR =
PKG_CONFIG_SYSROOT_DIR =
BUILD_CMD = kconfig
mcfg =
obj-y = kconfig/

CFLAGS = -O2 -g3 -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
	 -Werror-implicit-function-declaration -Wno-format-security -Wno-sign-compare \
	 -Wno-unused-but-set-variable -Wno-pointer-sign -Wno-format-overflow -Wno-dangling-pointer \
	 -DCURSES_LOC="<ncurses.h>" -DNCURSES_WIDECHAR=1 $(shell pkg-config --cflags ncursesw)
LDFLAGS = $(shell pkg-config --libs ncursesw)
endif

kconfig: all

help::
	echo ''
	echo 'KCONFIG'
	echo -e '$(GREEN)kconfig$(NORMAL)'
	echo -e '\tBuild kconfig tool'

.PHONY: kconfig
